package com.easy.user.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.easy.common.bean.SysRole;
import com.easy.common.bean.SysUser;
import com.easy.common.service.IUserService;
import com.easy.user.mapper.RoleMapper;
import com.easy.user.mapper.UserMapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
@DubboService
public class UserService extends ServiceImpl<UserMapper, SysUser> implements IUserService {
    @Autowired
    private RoleService roleService;
    @Autowired
    UserMapper userMapper;
    @Override
    public SysUser insert(SysUser user) {
        return null;
    }

    @Override
    public SysUser update(SysUser user) {
        return null;
    }

    @Override
    public int delete(Integer id) {
        return 0;
    }

    @Override
    public SysUser getByID(Integer id) {
        return null;
    }

    @Override
    public IPage<SysUser> getListByPage(IPage page, SysUser user) {
        return null;
    }

    @Override
    public List<SysUser> getList(SysUser user) {
        return null;
    }

    @Override
    public int setStatus(Integer id) {
        return 0;
    }

    @Override
    public SysUser assignRole(SysUser user) {
        return null;
    }

    @Override
    public SysUser getByUsername(String username) {
        SysUser user=super.getBaseMapper().getOneByUsername(username);
        user.setRole(getUserRoles(user));
        return user;
    }

    @Override
    public List<SysRole> getUserRoles(SysUser user) {
        List<SysRole> roles=this.getBaseMapper().getUserRoles(user.getId());
        for(SysRole role:roles){
            roleService.getRolePermissions(role);
        }
        return roles;
    }
}
